<include file="public/header"/>
<link rel="stylesheet" href="__STATIC__/css/weui.css"/> 
<link rel="stylesheet" href="__STATIC__/css/weui2.css"/> 
<link rel="stylesheet" href="//at.alicdn.com/t/font_p1m6wu3bwc23xr.css"/>
<style>
.td_l{display: flex;align-items: center;}
.td_l .nickname{margin-left:5px;}
.webox-li{background: #fff;overflow-y: scroll;}
.il_list > li{border-bottom: 1px solid #eee;}
</style>
<body style="background:#eee">
<div class="searchbar_wrap">
    <div class="weui_search_bar" id="search_bar">
                <form class="weui_search_outer">
                    <div class="weui_search_inner">
                        <i class="weui_icon_search"></i>
    <input class="weui_search_input" id="search_input" placeholder="搜索" required="" type="search">
                        <a href="javascript:" class="weui_icon_clear" id="search_clear"></a>
                    </div>
                    <label for="search_input" class="weui_search_text" id="search_text" onclick="this.style.display='none'">
                        <i class="weui_icon_search"></i>
                        <span>搜索</span>
                    </label>
                </form>
                <a href="javascript:" class="weui_search_cancel" id="search_cancel">取消</a>
            </div>
</div>
<div class="webox-li">
    <ul class="il_list all_score" id="J_il_list_1">
            
                        
    </ul>
</div>
<input type="hidden" name="type" id="type" value="{$type}">
</body>
</html>
<script src="__STATIC__/js/weui_zepto.min.js"></script>

<script>
 var bind_name = 'input';  
  if (navigator.userAgent.indexOf("MSIE") != -1){  
      bind_name = 'propertychange';  
  }
   var page = 1;
    // 每页展示10个
    var size =15;
  $("#search_input").bind(bind_name, function (event) {  
     var kw=$(this).val();
     if(kw.length>0&&kw!=''){
        $.get('{:U("User/search_user")}',{p:page,kw:kw,size:size},function(res){
           var obj=eval('(' + res + ')');
           var arrLen = obj.data.length;
               if(arrLen > 0){
                 $('#J_il_list_1').html(obj.data);
                 do_select();
               }
        })
     }
  })
 function do_select(){
    $('#J_il_list_1 li').click(function(){
        var headpic=$(this).find('.headpic').attr('src');
        var nickname=$(this).find('.nickname').text();
        var user_id=$(this).attr('data');
        if(user_id=='{$user.user_id}'){
            $.toast("不能选择自己","forbidden");
            return false;
        }
        var type="{$type}";
        if(type=='give_points'){
            $.prompt('<img src="'+headpic+'" width="40"><p>'+nickname+'</p>', "请确认，并输入要赠送积分", function(text) {
                    $.post('{:U("User/do_give")}',{points:text,user_id:user_id,type:'{$type}'},function(res){
                        if(res=="success"){
                            $.toast("转赠成功！");
                            setTimeout(function(){
                               history.back(-1);
                            },1000)
                        }else if(res=="not_points"){
                             $.toast("账户积分不足","forbidden");
                        }else if(res=="not_vip"){
                            $.alert("您的好友还不是会员，您可以邀请TA成为我们的会员后赠送！","温馨提示");
                        }else{
                            $.toast("转赠失败,稍后重试","forbidden");
                        }
                    })
                     // $.alert("您要:"+text, "请确认");
                    }, function() {
                      //取消操作
                    });
           
        }
         if(type=='give_coupon'){
            $.confirm('<img src="'+headpic+'" width="40"><p>'+nickname+'</p><div><select name="coupon" class="weui_select">{$coup_str}</select></div>', "请确认，并选择优惠券", function() {
              var coupon_id=$('.weui_select option:selected').val();
              $.post('{:U("User/do_give")}',{coupon_id:coupon_id,user_id:user_id,type:'{$type}'},function(res){
                    if(res=="success"){
                        $.toast("转赠成功！");
                        setTimeout(function(){
                           history.back(-1);
                        },1000)
                    }else if(res=="not_vip"){
                        $.alert("您的好友还不是会员，您可以邀请TA成为我们的会员后赠送！","温馨提示");
                    }else{
                        $.toast("转赠失败,稍后重试","forbidden");
                    }
              })
            }, function() {
              //取消操作
            });
         }
        
    
    })
 }

</script>       